<%@page import="vn.edu.ptithcm.pim.constant.Constants"%>
<script type="text/javascript">
var fileInfo = "";
function startUpload(id) {  
	var cmd = jQuery('input[name=cmd]').val();
	var title = jQuery('input[name=title]').val();
	if(title == ''){
		var msg = '<span class="v-error-message"><ul><li><spring:message code="message.missing.document.title" /></li></ul></span>';
		jQuery('#v-global-message').html(msg);
	}else{		
		var numberOfFiles = jQuery("#fileUploadsQueue").children().size();
		if(numberOfFiles == 0){
			if(cmd == 'add'){
				var msg = '<span class="v-error-message"><ul><li><spring:message code="required.document" /></li></ul></span>';
				jQuery('#v-global-message').html(msg);	
			}else if(cmd == 'edit'){
				submitForm('handleDocument');
			}
		}else{
		   jQuery('#v-global-message').html('');
		   jQuery('#' + id).uploadifyUpload();	
		}
	}
}

jQuery(document).ready(function(){
	   if (jQuery("#description").val() == 'null') {
			jQuery("#description").val('');
	   }

	    var requiredMajorVersion = 10;
	    var requiredMinorVersion = 0;
	    var requiredRevision = 0;
	    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	    if (!hasReqestedVersion) {
	      jQuery('#nosupportFlash').css("display", "block");
	      jQuery('#supportFlash').css("display", "none");
	      return;
	    }

	    jQuery("#fileUploads").uploadify({
	       'uploader': "<%=request.getContextPath()%>/swf/uploadify.swf",
	       'cancelImg': '<%=request.getContextPath()%>/images/cancel.png',
	       'script' : '<%=request.getContextPath()%>/ServletServer?type=<%=Constants.UPLOAD_FILES%>',  
	       'folder': '/UserData/Uploads',
	       'multi': false,
	       'sizeLimit': 10485760,
	       'queueSizeLimit': 1,
	       'removeCompleted': false,          
	       'displayData': 'percentage',
	       'expressInstall' : '<%=request.getContextPath()%>/swf/expressInstall.swf',
	       'fileExt': '*.*',
	       'fileDesc': '*.*',
	       
	       'onComplete': function (event, ID, fileObj, response, data) {        	 
	    	   fileInfo = response;
	       },
	       'onAllComplete': function (evt, data) {              
	           jQuery('input[name=fileInfo]').val(fileInfo);
	           submitForm('handleDocument');	
	       },
	       'onError': function (event, ID, fileObj, errorObj) {
	       }
	    });		
});
</script>